<?php
$screen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();
$basicInfoModel = new AddQueueLineFormModel('basicInfo');
$addChildModel = new AddQueueLineFormModel('addChildQueueLine');
$addResourceModel = new AddQueueLineFormModel('addResource');
$addTimeResourceModel = new AddQueueLineFormModel('addTimeResource');
$addQueueStrategyModel = new AddQueueLineFormModel('addQueueStrategy');

if (isset($_POST['AddQueueLineFormModel'])) {
    $basicInfoModel->attributes = $_POST['AddQueueLineFormModel'];
    $addChildModel->attributes = $_POST['AddQueueLineFormModel'];
    $addResourceModel->attributes = $_POST['AddQueueLineFormModel'];
    $addTimeResourceModel->attributes = $_POST['AddQueueLineFormModel'];
    $addQueueStrategyModel->attributes = $_POST['AddQueueLineFormModel'];
}

//add onetime queueline
if ($basicInfoModel->validate() && $addChildModel->validate()) {
    $screen->addChildQueueLine($basicInfoModel, $addChildModel);
}
if ($basicInfoModel->validate() && $addResourceModel->validate() && $addTimeResourceModel->validate() && $addQueueStrategyModel) {
    $screen->addQueueLine($basicInfoModel, $addResourceModel, $addTimeResourceModel, $addQueueStrategyModel);
}
?>
<script type="text/javascript">
    jQuery(function($) {
        $('#ql_type').change(function () {
            if($('#ql_type').val() == "newQL"){
                $("#newQL-div").toggle(true);
                $("#childQL-div").toggle(false);
            }
            if($('#ql_type').val() == "childQL"){
                $("#childQL-div").toggle(true);
                $("#newQL-div").toggle(false);
            }
            if($('#ql_type').val() == "noChoice"){
                $("#newQL-div").toggle(false);
                $("#childQL-div").toggle(false);
            }
        });      
        $('#ql_timeline').change(function () {
            if($('#ql_timeline').val() == "oneTimeQL"){
                $("#setCycleLength").toggle(false);  
            }
            if($('#ql_timeline').val() == "recursiveQL"){
                $("#setCycleLength").toggle(true);                
            }            
        });       
        $('#cbx_addChildQL').click(function () {    
            var checkResult = this.checked;
            $("#chooseParentQL_div").toggle(checkResult);          
        });        
        
        $('#dd_allocateTimeStrategy').change(function () {            
            if($('#dd_allocateTimeStrategy').val() == '<?php echo BOnlineQueueDbAdapter::Allocate_Queue_Strategy_On_Cycle; ?>'){
                $("#divQueueOnTimeSlot").toggle(false);
                $("#divQueueOnCycle").toggle(true);     
                $("#divDefineTimeSlot").toggle(false);
            }
            if($('#dd_allocateTimeStrategy').val() == '<?php echo BOnlineQueueDbAdapter::Allocate_Queue_Strategy_On_TimeSlot; ?>'){
                $("#divQueueOnTimeSlot").toggle(true);
                $("#divQueueOnCycle").toggle(false); 
                $("#divDefineTimeSlot").toggle(true);
            }            
        });   
        
        $('#dd_timeSlot').change(function () {
            if($('#dd_timeSlot').val() != "none"){
                $("#pickTimeSlot").toggle(true);             
            }
            if($('#dd_timeSlot').val() == "none"){
                $("#timeslot_day_period").toggle(false);
                $("#timeslot_week_period").toggle(false);
                $("#timeslot_minute_period").toggle(false);
                $("#timeslot_hour_period").toggle(false); 
                $("#pickTimeSlot").toggle(false); 
            }
            if($('#dd_timeSlot').val() == "minute"){
                $("#timeslot_day_period").toggle(false);
                $("#timeslot_week_period").toggle(false);
                $("#timeslot_minute_period").toggle(true);
                $("#timeslot_hour_period").toggle(false);                   
            }
            if($('#dd_timeSlot').val() == "hour"){
                $("#timeslot_day_period").toggle(false);
                $("#timeslot_week_period").toggle(false);
                $("#timeslot_minute_period").toggle(false);
                $("#timeslot_hour_period").toggle(true);                   
            }
            if($('#dd_timeSlot').val() == "day"){
                $("#timeslot_day_period").toggle(true);
                $("#timeslot_week_period").toggle(false);
                $("#timeslot_minute_period").toggle(false);
                $("#timeslot_hour_period").toggle(false);  
            }
            if($('#dd_timeSlot').val() == "week"){
                $("#timeslot_day_period").toggle(false);
                $("#timeslot_week_period").toggle(true);
                $("#timeslot_minute_period").toggle(false);
                $("#timeslot_hour_period").toggle(false);  
            }           
        });
        
        $('#dd_makequeue_cycle').change(function () {            
            if($('#dd_makequeue_cycle').val() == "sameMakeQueueCycle"){
                $("#divMakeQueueCycleExpression").toggle(false);               
            }
            if($('#dd_makequeue_cycle').val() == "customizedMakeQueueCycle"){
                $("#divMakeQueueCycleExpression").toggle(true);                
            }            
        });
        $('#dd_processqueue_cycle').change(function () {            
            if($('#dd_processqueue_cycle').val() == "sameProcessQueueCycle"){
                $("#divProcessQueueCycleExpression").toggle(false);               
            }
            if($('#dd_processqueue_cycle').val() == "customizedProcessQueueCycle"){
                $("#divProcessQueueCycleExpression").toggle(true);                
            }            
        });
        $('#dd_makequeue_timeslot').change(function () {            
            if($('#dd_makequeue_timeslot').val() == "sameMakeQueueTimeSlot"){
                $("#divMakeQueueTimeSlotExpression").toggle(false);               
            }
            if($('#dd_makequeue_timeslot').val() == "customizedMakeQueueTimeSlot"){
                $("#divMakeQueueTimeSlotExpression").toggle(true);                
            }            
        });
        $('#dd_processqueue_timeslot').change(function () {            
            if($('#dd_processqueue_timeslot').val() == "sameProcessQueueTimeSlot"){
                $("#divProcessQueueTimeSlotExpression").toggle(false);               
            }
            if($('#dd_processqueue_timeslot').val() == "customizedProcessQueueTimeSlot"){
                $("#divProcessQueueTimeSlotExpression").toggle(true);                
            }            
        });
        $('#dd_makequeue_strategy').change(function () {            
            if($('#dd_makequeue_strategy').val() == "makeQueueOnCycle"){
                $("#divMQT_Cycle").toggle(true);   
                $("#divMQT_TimeSlot").toggle(false); 
            }
            if($('#dd_makequeue_strategy').val() == "makeQueueOnTimeSlot"){
                $("#divMQT_Cycle").toggle(false);   
                $("#divMQT_TimeSlot").toggle(true);                
            }            
        });
        $('#dd_processqueue_strategy').change(function () {            
            if($('#dd_processqueue_strategy').val() == "processQueueOnCycle"){
                $("#divPQT_Cycle").toggle(true);   
                $("#divPQT_TimeSlot").toggle(false); 
            }
            if($('#dd_processqueue_strategy').val() == "processQueueOnTimeSlot"){
                $("#divPQT_Cycle").toggle(false);   
                $("#divPQT_TimeSlot").toggle(true);                
            }            
        });
    });    
</script>
<?php echo CHtml::beginForm(); ?>
<fieldset>
    <div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
        <ul class="nav nav-tabs" style="margin-bottom: 15px">
            <li class="active"><a href="#tab1" data-toggle="tab">Add basic info</a></li>
            <li><a href="#tab2" data-toggle="tab">Setup resource</a></li>
            <li><a href="#tab3" data-toggle="tab">Time resource</a></li>
            <li><a href="#tab4" data-toggle="tab">Queue strategy</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tab1" style="min-height: 270px">
                <div class="well">
                    <label>Queue-Line Name:</label>
                    <?php echo CHtml::activeTextField($basicInfoModel, 'queueLineName', array('placeholder' => 'Type name...', 'required' => true)); ?>                
                    <label>Description:</label>                
                    <?php echo CHtml::activeTextArea($basicInfoModel, 'queueLineDescription', array('placeholder' => 'Type description...')); ?>
                </div>
                <label class="checkbox">
                    <input id="cbx_addChildQL" type="checkbox">Is a child-queueline?
                </label>
                <div id="chooseParentQL_div" class="well" style="display: none">
                    <label>Select parent Queue-Line:</label>                    
                    <?php
                    echo CHtml::activeDropDownList($addChildModel, 'parentQueueLine', array('OverallQueueLine' => 'Overall Queue-Line',
                        'mobileQueueLine' => 'Mobile Queue-Line'));
                    ?>
                </div>
            </div>
            <div class="tab-pane" id="tab2" style="min-height: 270px">
                <div class="well">
                    <label>Resource Name:</label>
                    <?php echo CHtml::activeTextField($addResourceModel, 'queueLineResourceName', array('placeholder' => 'Type name...', 'required' => true)); ?>                
                    <label>Resource Description:</label>                
                    <?php echo CHtml::activeTextArea($addResourceModel, 'queueLineResourceDescription', array('placeholder' => 'Type description...')); ?>
                    <label>Resource Max QueueNumber:</label>                
                    <?php echo CHtml::activeTextField($addResourceModel, 'queueLineResourceMaxNumber', array('value' => '0')); ?>
                </div>
            </div>
            <div class="tab-pane" id="tab3" style="min-height: 270px">                 
                <div class="well">                                       
                    <label>Set Queue-Line Start Time:</label>                        
                    <?php echo CHtml::activeTextField($addTimeResourceModel, 'queueLineStartTime', array('placeholder' => "Type start time...")); ?>
                    <label>Set Queue-Line End Time:</label>   
                    <?php echo CHtml::activeTextField($addTimeResourceModel, 'queueLineEndTime', array('placeholder' => "Type end time...")); ?>
                    <div id="setCycleLength">
                        <label>Set Cycle Length(Expression):</label>
                        <?php echo CHtml::activeTextArea($addTimeResourceModel, 'queueLineCycleLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                    </div>
                    <div id="setCycleRepeatTimes">
                        <label>Set Cycle Repeat Times:</label>
                        <?php echo CHtml::activeTextField($addTimeResourceModel, 'queueLineCycleRepeatTimes', array('value' => "0")); ?>  
                    </div>                                                        
                </div>
            </div>           
            <div class="tab-pane" id="tab4" style="min-height: 270px">
                <div class="well">
                    <label>Allocate Time-Resource Strategy:</label>
                    <?php
                    echo CHtml::activeDropDownList($addQueueStrategyModel, 'allocateQueueStrategy', array(
                        BOnlineQueueDbAdapter::Allocate_Queue_Strategy_On_Cycle => 'Allocate queue on cycle',
                        BOnlineQueueDbAdapter::Allocate_Queue_Strategy_On_TimeSlot => 'Allocate queue on timeslot'), array('id' => 'dd_allocateTimeStrategy')
                    );
                    ?>
                    <div id="divDefineTimeSlot" style="display:none">
                        <label>Time Slot Length(Expression):</label>
                        <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'timeSlotLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                    </div> 
                    <div id="divQueueOnCycle">
                        <label>Define MakeQueue Cycle:</label>  
                        <div id="divMakeQueueOnCycle">
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'makeQueueCycleOption', array(
                                'sameMakeQueueCycle' => 'Same as queue cycle',
                                'customizedMakeQueueCycle' => 'Different with queue cycle',
                                    ), array('id' => 'dd_makequeue_cycle')
                            );
                            ?>
                        </div>
                        <div id="divMakeQueueCycleExpression" style="display:none">
                            <label>Offset to end of queue-line cycle</label>
                            <?php echo CHtml::activeTextField($addQueueStrategyModel, 'makeQueueCycleOffset', array('placeholder' => "Type offset")); ?>  
                            <label>MakeQueue Cycle Length(Expression):</label>
                            <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'makeQueueCycleLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[6,7]{h[9~12]}}', '' => true)); ?>
                        </div>
                        <div id="divProcessQueueOnCycle">
                            <label>Define ProcessQueue Cycle:</label>  
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'processQueueCycleOption', array(
                                'sameProcessQueueCycle' => 'Same as queue cycle',
                                'customizedProcessQueueCycle' => 'Different with queue cycle',
                                    ), array('id' => 'dd_processqueue_cycle')
                            );
                            ?>
                        </div>
                        <div id="divProcessQueueCycleExpression" style="display:none">
                            <label>Offset to end of queue-line cycle</label>
                            <?php echo CHtml::activeTextField($addQueueStrategyModel, 'processQueueCycleOffset', array('placeholder' => "Type offset")); ?>
                            <label>ProcessQueue Cycle Length(Expression):</label>
                            <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'processQueueCycleLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                        </div>
                    </div>
                    <div id="divQueueOnTimeSlot" style="display: none">
                        <label>TimeSlot Based MakeQueue cycle define:</label>  
                        <div id="divMakeQueueOnTimeSlot">
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'makeQueueTimeSlotOption', array(
                                'sameMakeQueueTimeSlot' => 'Same as queue cycle',
                                'customizedMakeQueueTimeSlot' => 'Different with queue cycle',
                                    ), array('id' => 'dd_makequeue_timeslot')
                            );
                            ?>
                        </div>
                        <div id="divMakeQueueTimeSlotExpression" style="display:none">
                            <label>MakeQueue Stragegy:</label>
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'makeQueueStrategy', array(
                                'makeQueueOnCycle' => 'MakeQueue Duration By Cycle',
                                'makeQueueOnTimeSlot' => 'MakeQueue Duration By TimeSlot',
                                    ), array('id' => 'dd_makequeue_strategy')
                            );
                            ?>

                            <div id="divMQT_Cycle">
                                <label>Offset To End Of Queue-Line Cycle</label>
                                <?php echo CHtml::activeTextField($addQueueStrategyModel, 'makeQueueCycleOffset2', array('placeholder' => "Type offset")); ?>
                                <label>MakeQueue Cycle Length(Expression):</label>
                                <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'makeQueueCycleLength2', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                            </div>
                            <div id="divMQT_TimeSlot" style="display: none">
                                <label>Offset To End Of Queue-Line TimeSlot</label>
                                <?php echo CHtml::activeTextField($addQueueStrategyModel, 'makeQueueTimeSlotOffset', array('placeholder' => "Type offset")); ?>
                                <label>MakeQueue TimeSlot Length(Expression):</label>
                                <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'makeQueueTimeSlotLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                            </div>
                        </div>
                        <div id="divProcessQueueOnTimeSlot">
                            <label>TimeSlot Based ProcessQueue cycle define:</label>  
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'processQueueTimeSlotOption', array(
                                'sameProcessQueueTimeSlot' => 'Same as queue timeslot',
                                'customizedProcessQueueTimeSlot' => 'Different with queue timeslot',
                                    ), array('id' => 'dd_processqueue_timeslot')
                            );
                            ?>
                        </div>
                        <div id="divProcessQueueTimeSlotExpression" style="display:none">
                            <label>ProcessQueue Strategy:</label>                            
                            <?php
                            echo CHtml::activeDropDownList($addQueueStrategyModel, 'processQueueStrategy', array(
                                'processQueueOnCycle' => 'ProcessQueue Duration By Cycle',
                                'processQueueOnTimeSlot' => 'ProcessQueue Duration By TimeSlot',
                                    ), array('id' => 'dd_processqueue_strategy')
                            );
                            ?>
                            <div id="divPQT_Cycle">
                                <label>Offset To End Of Queue-Line Cycle</label>
                                <?php echo CHtml::activeTextField($addQueueStrategyModel, 'processQueueCycleOffset2', array('placeholder' => "Type offset")); ?>
                                <label>ProcessQueue Cycle Length(Expression):</label>
                                <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'processQueueCycleLength2', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                            </div>
                            <div id="divPQT_TimeSlot" style="display: none">
                                <label>Offset To End Of Queue-Line TimeSlot</label>
                                <?php echo CHtml::activeTextField($addQueueStrategyModel, 'processQueueTimeSlotOffset', array('placeholder' => "Type offset")); ?>
                                <label>ProcessQueue TimeSlot Length(Expression):</label>
                                <?php echo CHtml::activeTextArea($addQueueStrategyModel, 'processQueueTimeSlotLength', array('placeholder' => 'w{d[1~5]{h[9~18]},d[5,6]{h[9~12]}}', '' => true)); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="span2"><?php echo CHtml::submitButton('Submit', array('class' => 'btn')); ?></div>
        <div class="span2"><?php echo CHtml::resetButton('Reset', array('class' => 'btn')); ?></div>
</fieldset>
<?php echo CHtml::endForm(); ?>


